<?php

namespace app\admin\controller\user\party;

use app\common\controller\Backend;
use PhpOffice\PhpSpreadsheet\IOFactory;
use think\Response;
use think\Db;
use think\Log;
use think\Loader;
use fast\Random;

/**
 * 党员信息
 *
 * @icon fa fa-circle-o
 */
class Examine extends Backend
{

    /**
     * Member模型对象
     * @var \app\admin\model\user\party\Examine
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\user\party\Examine;
        $this->view->assign("typeList", $this->model->getTypeList());
        $this->view->assign("statusList", $this->model->getStatusList());
        $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http';
        $domain = $_SERVER['HTTP_HOST'];
        $url = $protocol . '://' . $domain;
        $site = config('site');
        $this->view->assign("party_member", $site['party_member']);
        $this->view->assign("url", $url);
    }



    /**
     * 查看
     */
    public function index()
    {
        //当前是否为关联查询
        $this->relationSearch = true;
        //设置过滤方法
        $this->request->filter(['strip_tags', 'trim']);
        if ($this->request->isAjax()) {
            //如果发送的来源是Selectpage，则转发到Selectpage
            if ($this->request->request('keyField')) {
                return $this->selectpage();
            }
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
            $list = $this->model
                ->with(['user', 'userinfo'])
                ->where($this->model->getTable() . '.status', '0')
                ->where($where)
                ->order($sort, $order)
                ->paginate($limit);
            $result = array("total" => $list->total(), "rows" => $list->items());

            return json($result);
        }
        return $this->view->fetch();
    }

    /**
     * 详情
     */
    public function detail($ids = '')
    {
        if ($this->request->isPost()) {
            $edit = $this->model->get($ids);
            $params = $this->request->post("row/a");
            if ($edit['type'] > 1) {
                if ($edit['party_application_time']) {
                    $params['type'] = 5;
                }
                if ($edit['party_active_time']) {
                    $params['type'] = 4;
                }
                if ($edit['party_develop_time']) {
                    $params['type'] = 3;
                }
                if ($edit['party_member_time']) {
                    $params['type'] = 2;
                }
                if ($edit['zjoining_time']) {
                    $params['type'] = 1;
                }
            }
            $params['update_time'] = time();
            if ($edit->allowField(true)->save($params)) {
                $this->success(__('修改成功'));
            }
            $this->error(__('操作失败！'));
        }
        $data = $this->model
            ->with(['user', 'userinfo'])
            ->where($this->model->getTable() . '.id', $ids)
            ->find();
        $this->view->assign("data", $data);

        return $this->view->fetch();
    }
}
